home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gperf.idb / usr / freeware / info / gperf.info.z / gperf.info
Text File  |  2002-10-07  |  63KB  |  1,390 lines

  1. This is gperf.info, produced by makeinfo version 4.0 from gperf.texi.
  2.  
  3. INFO-DIR-SECTION Programming Tools
  4. START-INFO-DIR-ENTRY
  5. * Gperf: (gperf).                Perfect Hash Function Generator.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the features of the GNU Perfect Hash Function
  9. Generator 2.7.2.
  10.  
  11.    Copyright (C) 1989-2000 Free Software Foundation, Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided also
  19. that the section entitled "GNU General Public License" is included
  20. exactly as in the original, and provided that the entire resulting
  21. derived work is distributed under the terms of a permission notice
  22. identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that the section entitled "GNU General Public License"
  27. and this permission notice may be included in translations approved by
  28. the Free Software Foundation instead of in the original English.
  29.  
  30. 
  31. File: gperf.info,  Node: Top,  Next: Copying,  Prev: (dir),  Up: (dir)
  32.  
  33. Introduction
  34. ************
  35.  
  36.    This manual documents the GNU `gperf' perfect hash function generator
  37. utility, focusing on its features and how to use them, and how to report
  38. bugs.
  39.  
  40. * Menu:
  41.  
  42. * Copying::                     GNU `gperf' General Public License says
  43.                                 how you can copy and share `gperf'.
  44. * Contributors::                People who have contributed to `gperf'.
  45. * Motivation::                  Static search structures and GNU GPERF.
  46. * Search Structures::           Static search structures and GNU `gperf'
  47. * Description::                 High-level discussion of how GPERF functions.
  48. * Options::                     A description of options to the program.
  49. * Bugs::                        Known bugs and limitations with GPERF.
  50. * Projects::                    Things still left to do.
  51. * Implementation::              Implementation Details for GNU GPERF.
  52. * Bibliography::                Material Referenced in this Report.
  53.  
  54. * Concept Index::
  55.  
  56.  
  57. High-Level Description of GNU `gperf'
  58.  
  59. * Input Format::                Input Format to `gperf'
  60. * Output Format::               Output Format for Generated C Code with `gperf'
  61. * Binary Strings::              Use of NUL characters
  62.  
  63. Input Format to `gperf'
  64.  
  65. * Declarations::                `struct' Declarations and C Code Inclusion.
  66. * Keywords::                    Format for Keyword Entries.
  67. * Functions::                   Including Additional C Functions.
  68.  
  69. Invoking `gperf'
  70.  
  71. * Input Details::               Options that affect Interpretation of the Input File
  72. * Output Language::             Specifying the Language for the Output Code
  73. * Output Details::              Fine tuning Details in the Output Code
  74. * Algorithmic Details::         Changing the Algorithms employed by `gperf'
  75. * Verbosity::                   Informative Output
  76.  
  77. 
  78. File: gperf.info,  Node: Copying,  Next: Contributors,  Prev: Top,  Up: Top
  79.  
  80. GNU GENERAL PUBLIC LICENSE
  81. **************************
  82.  
  83.                          Version 2, June 1991
  84.  
  85.      Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
  86.      59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  87.      
  88.      Everyone is permitted to copy and distribute verbatim copies
  89.      of this license document, but changing it is not allowed.
  90.  
  91. Preamble
  92. ========
  93.  
  94.    The licenses for most software are designed to take away your
  95. freedom to share and change it.  By contrast, the GNU General Public
  96. License is intended to guarantee your freedom to share and change free
  97. software--to make sure the software is free for all its users.  This
  98. General Public License applies to most of the Free Software
  99. Foundation's software and to any other program whose authors commit to
  100. using it.  (Some other Free Software Foundation software is covered by
  101. the GNU Library General Public License instead.)  You can apply it to
  102. your programs, too.
  103.  
  104.    When we speak of free software, we are referring to freedom, not
  105. price.  Our General Public Licenses are designed to make sure that you
  106. have the freedom to distribute copies of free software (and charge for
  107. this service if you wish), that you receive source code or can get it
  108. if you want it, that you can change the software or use pieces of it in
  109. new free programs; and that you know you can do these things.
  110.  
  111.    To protect your rights, we need to make restrictions that forbid
  112. anyone to deny you these rights or to ask you to surrender the rights.
  113. These restrictions translate to certain responsibilities for you if you
  114. distribute copies of the software, or if you modify it.
  115.  
  116.    For example, if you distribute copies of such a program, whether
  117. gratis or for a fee, you must give the recipients all the rights that
  118. you have.  You must make sure that they, too, receive or can get the
  119. source code.  And you must show them these terms so they know their
  120. rights.
  121.  
  122.    We protect your rights with two steps: (1) copyright the software,
  123. and (2) offer you this license which gives you legal permission to copy,
  124. distribute and/or modify the software.
  125.  
  126.    Also, for each author's protection and ours, we want to make certain
  127. that everyone understands that there is no warranty for this free
  128. software.  If the software is modified by someone else and passed on, we
  129. want its recipients to know that what they have is not the original, so
  130. that any problems introduced by others will not reflect on the original
  131. authors' reputations.
  132.  
  133.    Finally, any free program is threatened constantly by software
  134. patents.  We wish to avoid the danger that redistributors of a free
  135. program will individually obtain patent licenses, in effect making the
  136. program proprietary.  To prevent this, we have made it clear that any
  137. patent must be licensed for everyone's free use or not licensed at all.
  138.  
  139.    The precise terms and conditions for copying, distribution and
  140. modification follow.
  141.  
  142.     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  143.  
  144.   0. This License applies to any program or other work which contains a
  145.      notice placed by the copyright holder saying it may be distributed
  146.      under the terms of this General Public License.  The "Program",
  147.      below, refers to any such program or work, and a "work based on
  148.      the Program" means either the Program or any derivative work under
  149.      copyright law: that is to say, a work containing the Program or a
  150.      portion of it, either verbatim or with modifications and/or
  151.      translated into another language.  (Hereinafter, translation is
  152.      included without limitation in the term "modification".)  Each
  153.      licensee is addressed as "you".
  154.  
  155.      Activities other than copying, distribution and modification are
  156.      not covered by this License; they are outside its scope.  The act
  157.      of running the Program is not restricted, and the output from the
  158.      Program is covered only if its contents constitute a work based on
  159.      the Program (independent of having been made by running the
  160.      Program).  Whether that is true depends on what the Program does.
  161.  
  162.   1. You may copy and distribute verbatim copies of the Program's
  163.      source code as you receive it, in any medium, provided that you
  164.      conspicuously and appropriately publish on each copy an appropriate
  165.      copyright notice and disclaimer of warranty; keep intact all the
  166.      notices that refer to this License and to the absence of any
  167.      warranty; and give any other recipients of the Program a copy of
  168.      this License along with the Program.
  169.  
  170.      You may charge a fee for the physical act of transferring a copy,
  171.      and you may at your option offer warranty protection in exchange
  172.      for a fee.
  173.  
  174.   2. You may modify your copy or copies of the Program or any portion
  175.      of it, thus forming a work based on the Program, and copy and
  176.      distribute such modifications or work under the terms of Section 1
  177.      above, provided that you also meet all of these conditions:
  178.  
  179.        a. You must cause the modified files to carry prominent notices
  180.           stating that you changed the files and the date of any change.
  181.  
  182.        b. You must cause any work that you distribute or publish, that
  183.           in whole or in part contains or is derived from the Program
  184.           or any part thereof, to be licensed as a whole at no charge
  185.           to all third parties under the terms of this License.
  186.  
  187.        c. If the modified program normally reads commands interactively
  188.           when run, you must cause it, when started running for such
  189.           interactive use in the most ordinary way, to print or display
  190.           an announcement including an appropriate copyright notice and
  191.           a notice that there is no warranty (or else, saying that you
  192.           provide a warranty) and that users may redistribute the
  193.           program under these conditions, and telling the user how to
  194.           view a copy of this License.  (Exception: if the Program
  195.           itself is interactive but does not normally print such an
  196.           announcement, your work based on the Program is not required
  197.           to print an announcement.)
  198.  
  199.      These requirements apply to the modified work as a whole.  If
  200.      identifiable sections of that work are not derived from the
  201.      Program, and can be reasonably considered independent and separate
  202.      works in themselves, then this License, and its terms, do not
  203.      apply to those sections when you distribute them as separate
  204.      works.  But when you distribute the same sections as part of a
  205.      whole which is a work based on the Program, the distribution of
  206.      the whole must be on the terms of this License, whose permissions
  207.      for other licensees extend to the entire whole, and thus to each
  208.      and every part regardless of who wrote it.
  209.  
  210.      Thus, it is not the intent of this section to claim rights or
  211.      contest your rights to work written entirely by you; rather, the
  212.      intent is to exercise the right to control the distribution of
  213.      derivative or collective works based on the Program.
  214.  
  215.      In addition, mere aggregation of another work not based on the
  216.      Program with the Program (or with a work based on the Program) on
  217.      a volume of a storage or distribution medium does not bring the
  218.      other work under the scope of this License.
  219.  
  220.   3. You may copy and distribute the Program (or a work based on it,
  221.      under Section 2) in object code or executable form under the terms
  222.      of Sections 1 and 2 above provided that you also do one of the
  223.      following:
  224.  
  225.        a. Accompany it with the complete corresponding machine-readable
  226.           source code, which must be distributed under the terms of
  227.           Sections 1 and 2 above on a medium customarily used for
  228.           software interchange; or,
  229.  
  230.        b. Accompany it with a written offer, valid for at least three
  231.           years, to give any third party, for a charge no more than your
  232.           cost of physically performing source distribution, a complete
  233.           machine-readable copy of the corresponding source code, to be
  234.           distributed under the terms of Sections 1 and 2 above on a
  235.           medium customarily used for software interchange; or,
  236.  
  237.        c. Accompany it with the information you received as to the offer
  238.           to distribute corresponding source code.  (This alternative is
  239.           allowed only for noncommercial distribution and only if you
  240.           received the program in object code or executable form with
  241.           such an offer, in accord with Subsection b above.)
  242.  
  243.      The source code for a work means the preferred form of the work for
  244.      making modifications to it.  For an executable work, complete
  245.      source code means all the source code for all modules it contains,
  246.      plus any associated interface definition files, plus the scripts
  247.      used to control compilation and installation of the executable.
  248.      However, as a special exception, the source code distributed need
  249.      not include anything that is normally distributed (in either
  250.      source or binary form) with the major components (compiler,
  251.      kernel, and so on) of the operating system on which the executable
  252.      runs, unless that component itself accompanies the executable.
  253.  
  254.      If distribution of executable or object code is made by offering
  255.      access to copy from a designated place, then offering equivalent
  256.      access to copy the source code from the same place counts as
  257.      distribution of the source code, even though third parties are not
  258.      compelled to copy the source along with the object code.
  259.  
  260.   4. You may not copy, modify, sublicense, or distribute the Program
  261.      except as expressly provided under this License.  Any attempt
  262.      otherwise to copy, modify, sublicense or distribute the Program is
  263.      void, and will automatically terminate your rights under this
  264.      License.  However, parties who have received copies, or rights,
  265.      from you under this License will not have their licenses
  266.      terminated so long as such parties remain in full compliance.
  267.  
  268.   5. You are not required to accept this License, since you have not
  269.      signed it.  However, nothing else grants you permission to modify
  270.      or distribute the Program or its derivative works.  These actions
  271.      are prohibited by law if you do not accept this License.
  272.      Therefore, by modifying or distributing the Program (or any work
  273.      based on the Program), you indicate your acceptance of this
  274.      License to do so, and all its terms and conditions for copying,
  275.      distributing or modifying the Program or works based on it.
  276.  
  277.   6. Each time you redistribute the Program (or any work based on the
  278.      Program), the recipient automatically receives a license from the
  279.      original licensor to copy, distribute or modify the Program
  280.      subject to these terms and conditions.  You may not impose any
  281.      further restrictions on the recipients' exercise of the rights
  282.      granted herein.  You are not responsible for enforcing compliance
  283.      by third parties to this License.
  284.  
  285.   7. If, as a consequence of a court judgment or allegation of patent
  286.      infringement or for any other reason (not limited to patent
  287.      issues), conditions are imposed on you (whether by court order,
  288.      agreement or otherwise) that contradict the conditions of this
  289.      License, they do not excuse you from the conditions of this
  290.      License.  If you cannot distribute so as to satisfy simultaneously
  291.      your obligations under this License and any other pertinent
  292.      obligations, then as a consequence you may not distribute the
  293.      Program at all.  For example, if a patent license would not permit
  294.      royalty-free redistribution of the Program by all those who
  295.      receive copies directly or indirectly through you, then the only
  296.      way you could satisfy both it and this License would be to refrain
  297.      entirely from distribution of the Program.
  298.  
  299.      If any portion of this section is held invalid or unenforceable
  300.      under any particular circumstance, the balance of the section is
  301.      intended to apply and the section as a whole is intended to apply
  302.      in other circumstances.
  303.  
  304.      It is not the purpose of this section to induce you to infringe any
  305.      patents or other property right claims or to contest validity of
  306.      any such claims; this section has the sole purpose of protecting
  307.      the integrity of the free software distribution system, which is
  308.      implemented by public license practices.  Many people have made
  309.      generous contributions to the wide range of software distributed
  310.      through that system in reliance on consistent application of that
  311.      system; it is up to the author/donor to decide if he or she is
  312.      willing to distribute software through any other system and a
  313.      licensee cannot impose that choice.
  314.  
  315.      This section is intended to make thoroughly clear what is believed
  316.      to be a consequence of the rest of this License.
  317.  
  318.   8. If the distribution and/or use of the Program is restricted in
  319.      certain countries either by patents or by copyrighted interfaces,
  320.      the original copyright holder who places the Program under this
  321.      License may add an explicit geographical distribution limitation
  322.      excluding those countries, so that distribution is permitted only
  323.      in or among countries not thus excluded.  In such case, this
  324.      License incorporates the limitation as if written in the body of
  325.      this License.
  326.  
  327.   9. The Free Software Foundation may publish revised and/or new
  328.      versions of the General Public License from time to time.  Such
  329.      new versions will be similar in spirit to the present version, but
  330.      may differ in detail to address new problems or concerns.
  331.  
  332.      Each version is given a distinguishing version number.  If the
  333.      Program specifies a version number of this License which applies
  334.      to it and "any later version", you have the option of following
  335.      the terms and conditions either of that version or of any later
  336.      version published by the Free Software Foundation.  If the Program
  337.      does not specify a version number of this License, you may choose
  338.      any version ever published by the Free Software Foundation.
  339.  
  340.  10. If you wish to incorporate parts of the Program into other free
  341.      programs whose distribution conditions are different, write to the
  342.      author to ask for permission.  For software which is copyrighted
  343.      by the Free Software Foundation, write to the Free Software
  344.      Foundation; we sometimes make exceptions for this.  Our decision
  345.      will be guided by the two goals of preserving the free status of
  346.      all derivatives of our free software and of promoting the sharing
  347.      and reuse of software generally.
  348.  
  349.                                 NO WARRANTY
  350.  
  351.  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  352.      WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  353.      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  354.      HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  355.      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  356.      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  357.      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  358.      QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  359.      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  360.      SERVICING, REPAIR OR CORRECTION.
  361.  
  362.  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  363.      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  364.      MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  365.      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  366.      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  367.      INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  368.      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  369.      OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  370.      OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  371.      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  372.  
  373.                       END OF TERMS AND CONDITIONS
  374.  
  375. How to Apply These Terms to Your New Programs
  376. =============================================
  377.  
  378.    If you develop a new program, and you want it to be of the greatest
  379. possible use to the public, the best way to achieve this is to make it
  380. free software which everyone can redistribute and change under these
  381. terms.
  382.  
  383.    To do so, attach the following notices to the program.  It is safest
  384. to attach them to the start of each source file to most effectively
  385. convey the exclusion of warranty; and each file should have at least
  386. the "copyright" line and a pointer to where the full notice is found.
  387.  
  388.      ONE LINE TO GIVE THE PROGRAM'S NAME AND AN IDEA OF WHAT IT DOES.
  389.      Copyright (C) YEAR  NAME OF AUTHOR
  390.      
  391.      This program is free software; you can redistribute it and/or
  392.      modify it under the terms of the GNU General Public License
  393.      as published by the Free Software Foundation; either version 2
  394.      of the License, or (at your option) any later version.
  395.      
  396.      This program is distributed in the hope that it will be useful,
  397.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  398.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  399.      GNU General Public License for more details.
  400.      
  401.      You should have received a copy of the GNU General Public License
  402.      along with this program; if not, write to the Free Software
  403.      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  404.  
  405.    Also add information on how to contact you by electronic and paper
  406. mail.
  407.  
  408.    If the program is interactive, make it output a short notice like
  409. this when it starts in an interactive mode:
  410.  
  411.      Gnomovision version 69, Copyright (C) YEAR  NAME OF AUTHOR
  412.      Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
  413.      type `show w'.  This is free software, and you are welcome
  414.      to redistribute it under certain conditions; type `show c'
  415.      for details.
  416.  
  417.    The hypothetical commands `show w' and `show c' should show the
  418. appropriate parts of the General Public License.  Of course, the
  419. commands you use may be called something other than `show w' and `show
  420. c'; they could even be mouse-clicks or menu items--whatever suits your
  421. program.
  422.  
  423.    You should also get your employer (if you work as a programmer) or
  424. your school, if any, to sign a "copyright disclaimer" for the program,
  425. if necessary.  Here is a sample; alter the names:
  426.  
  427.      Yoyodyne, Inc., hereby disclaims all copyright
  428.      interest in the program `Gnomovision'
  429.      (which makes passes at compilers) written
  430.      by James Hacker.
  431.      
  432.      SIGNATURE OF TY COON, 1 April 1989
  433.      Ty Coon, President of Vice
  434.  
  435.    This General Public License does not permit incorporating your
  436. program into proprietary programs.  If your program is a subroutine
  437. library, you may consider it more useful to permit linking proprietary
  438. applications with the library.  If this is what you want to do, use the
  439. GNU Library General Public License instead of this License.
  440.  
  441. 
  442. File: gperf.info,  Node: Contributors,  Next: Motivation,  Prev: Copying,  Up: Top
  443.  
  444. Contributors to GNU `gperf' Utility
  445. ***********************************
  446.  
  447.    * The GNU `gperf' perfect hash function generator utility was
  448.      originally written in GNU C++ by Douglas C. Schmidt.  It is now
  449.      also available in a highly-portable "old-style" C version.  The
  450.      general idea for the perfect hash function generator was inspired
  451.      by Keith Bostic's algorithm written in C, and distributed to
  452.      net.sources around 1984.  The current program is a heavily
  453.      modified, enhanced, and extended implementation of Keith's basic
  454.      idea, created at the University of California, Irvine.  Bugs,
  455.      patches, and suggestions should be reported to both
  456.      `<bug-gnu-utils@gnu.org>' and `<gperf-bugs@lists.sourceforge.net>'.
  457.  
  458.    * Special thanks is extended to Michael Tiemann and Doug Lea, for
  459.      providing a useful compiler, and for giving me a forum to exhibit
  460.      my creation.
  461.  
  462.      In addition, Adam de Boor and Nels Olson provided many tips and
  463.      insights that greatly helped improve the quality and functionality
  464.      of `gperf'.
  465.  
  466.    * A testsuite was added by Bruno Haible. He also rewrote the output
  467.      routines for better reliability.
  468.  
  469. 
  470. File: gperf.info,  Node: Motivation,  Next: Search Structures,  Prev: Contributors,  Up: Top
  471.  
  472. Introduction
  473. ************
  474.  
  475.    `gperf' is a perfect hash function generator written in C++.  It
  476. transforms an N element user-specified keyword set W into a perfect
  477. hash function F.  F uniquely maps keywords in W onto the range 0..K,
  478. where K >= N.  If K = N then F is a _minimal_ perfect hash function.
  479. `gperf' generates a 0..K element static lookup table and a pair of C
  480. functions.  These functions determine whether a given character string
  481. S occurs in W, using at most one probe into the lookup table.
  482.  
  483.    `gperf' currently generates the reserved keyword recognizer for
  484. lexical analyzers in several production and research compilers and
  485. language processing tools, including GNU C, GNU C++, GNU Pascal, GNU
  486. Modula 3, and GNU indent.  Complete C++ source code for `gperf' is
  487. available via anonymous ftp from `ftp://ftp.gnu.org/pub/gnu/gperf/'.  A
  488. paper describing `gperf''s design and implementation in greater detail
  489. is available in the Second USENIX C++ Conference proceedings.
  490.  
  491. 
  492. File: gperf.info,  Node: Search Structures,  Next: Description,  Prev: Motivation,  Up: Top
  493.  
  494. Static search structures and GNU `gperf'
  495. ****************************************
  496.  
  497.    A "static search structure" is an Abstract Data Type with certain
  498. fundamental operations, e.g., _initialize_, _insert_, and _retrieve_.
  499. Conceptually, all insertions occur before any retrievals.  In practice,
  500. `gperf' generates a `static' array containing search set keywords and
  501. any associated attributes specified by the user.  Thus, there is
  502. essentially no execution-time cost for the insertions.  It is a useful
  503. data structure for representing _static search sets_.  Static search
  504. sets occur frequently in software system applications.  Typical static
  505. search sets include compiler reserved words, assembler instruction
  506. opcodes, and built-in shell interpreter commands.  Search set members,
  507. called "keywords", are inserted into the structure only once, usually
  508. during program initialization, and are not generally modified at
  509. run-time.
  510.  
  511.    Numerous static search structure implementations exist, e.g.,
  512. arrays, linked lists, binary search trees, digital search tries, and
  513. hash tables.  Different approaches offer trade-offs between space
  514. utilization and search time efficiency.  For example, an N element
  515. sorted array is space efficient, though the average-case time
  516. complexity for retrieval operations using binary search is proportional
  517. to log N.  Conversely, hash table implementations often locate a table
  518. entry in constant time, but typically impose additional memory overhead
  519. and exhibit poor worst case performance.
  520.  
  521.    _Minimal perfect hash functions_ provide an optimal solution for a
  522. particular class of static search sets.  A minimal perfect hash
  523. function is defined by two properties:
  524.  
  525.    * It allows keyword recognition in a static search set using at most
  526.      _one_ probe into the hash table.  This represents the "perfect"
  527.      property.
  528.  
  529.    * The actual memory allocated to store the keywords is precisely
  530.      large enough for the keyword set, and _no larger_.  This is the
  531.      "minimal" property.
  532.  
  533.    For most applications it is far easier to generate _perfect_ hash
  534. functions than _minimal perfect_ hash functions.  Moreover, non-minimal
  535. perfect hash functions frequently execute faster than minimal ones in
  536. practice.  This phenomena occurs since searching a sparse keyword table
  537. increases the probability of locating a "null" entry, thereby reducing
  538. string comparisons.  `gperf''s default behavior generates
  539. _near-minimal_ perfect hash functions for keyword sets.  However,
  540. `gperf' provides many options that permit user control over the degree
  541. of minimality and perfection.
  542.  
  543.    Static search sets often exhibit relative stability over time.  For
  544. example, Ada's 63 reserved words have remained constant for nearly a
  545. decade.  It is therefore frequently worthwhile to expend concerted
  546. effort building an optimal search structure _once_, if it subsequently
  547. receives heavy use multiple times.  `gperf' removes the drudgery
  548. associated with constructing time- and space-efficient search
  549. structures by hand.  It has proven a useful and practical tool for
  550. serious programming projects.  Output from `gperf' is currently used in
  551. several production and research compilers, including GNU C, GNU C++,
  552. GNU Pascal, and GNU Modula 3.  The latter two compilers are not yet
  553. part of the official GNU distribution.  Each compiler utilizes `gperf'
  554. to automatically generate static search structures that efficiently
  555. identify their respective reserved keywords.
  556.  
  557. 
  558. File: gperf.info,  Node: Description,  Next: Options,  Prev: Search Structures,  Up: Top
  559.  
  560. High-Level Description of GNU `gperf'
  561. *************************************
  562.  
  563. * Menu:
  564.  
  565. * Input Format::                Input Format to `gperf'
  566. * Output Format::               Output Format for Generated C Code with `gperf'
  567. * Binary Strings::              Use of NUL characters
  568.  
  569.    The perfect hash function generator `gperf' reads a set of
  570. "keywords" from a "keyfile" (or from the standard input by default).
  571. It attempts to derive a perfect hashing function that recognizes a
  572. member of the "static keyword set" with at most a single probe into the
  573. lookup table.  If `gperf' succeeds in generating such a function it
  574. produces a pair of C source code routines that perform hashing and
  575. table lookup recognition.  All generated C code is directed to the
  576. standard output.  Command-line options described below allow you to
  577. modify the input and output format to `gperf'.
  578.  
  579.    By default, `gperf' attempts to produce time-efficient code, with
  580. less emphasis on efficient space utilization.  However, several options
  581. exist that permit trading-off execution time for storage space and vice
  582. versa.  In particular, expanding the generated table size produces a
  583. sparse search structure, generally yielding faster searches.
  584. Conversely, you can direct `gperf' to utilize a C `switch' statement
  585. scheme that minimizes data space storage size.  Furthermore, using a C
  586. `switch' may actually speed up the keyword retrieval time somewhat.
  587. Actual results depend on your C compiler, of course.
  588.  
  589.    In general, `gperf' assigns values to the characters it is using for
  590. hashing until some set of values gives each keyword a unique value.  A
  591. helpful heuristic is that the larger the hash value range, the easier
  592. it is for `gperf' to find and generate a perfect hash function.
  593. Experimentation is the key to getting the most from `gperf'.
  594.  
  595. 
  596. File: gperf.info,  Node: Input Format,  Next: Output Format,  Prev: Description,  Up: Description
  597.  
  598. Input Format to `gperf'
  599. =======================
  600.  
  601.    You can control the input keyfile format by varying certain
  602. command-line arguments, in particular the `-t' option.  The input's
  603. appearance is similar to GNU utilities `flex' and `bison' (or UNIX
  604. utilities `lex' and `yacc').  Here's an outline of the general format:
  605.  
  606.      declarations
  607.      %%
  608.      keywords
  609.      %%
  610.      functions
  611.  
  612.    _Unlike_ `flex' or `bison', all sections of `gperf''s input are
  613. optional.  The following sections describe the input format for each
  614. section.
  615.  
  616. * Menu:
  617.  
  618. * Declarations::                `struct' Declarations and C Code Inclusion.
  619. * Keywords::                    Format for Keyword Entries.
  620. * Functions::                   Including Additional C Functions.
  621.  
  622. 
  623. File: gperf.info,  Node: Declarations,  Next: Keywords,  Prev: Input Format,  Up: Input Format
  624.  
  625. `struct' Declarations and C Code Inclusion
  626. ------------------------------------------
  627.  
  628.    The keyword input file optionally contains a section for including
  629. arbitrary C declarations and definitions, as well as provisions for
  630. providing a user-supplied `struct'.  If the `-t' option _is_ enabled,
  631. you _must_ provide a C `struct' as the last component in the
  632. declaration section from the keyfile file.  The first field in this
  633. struct must be a `char *' or `const char *' identifier called `name',
  634. although it is possible to modify this field's name with the `-K'
  635. option described below.
  636.  
  637.    Here is a simple example, using months of the year and their
  638. attributes as input:
  639.  
  640.      struct months { char *name; int number; int days; int leap_days; };
  641.      %%
  642.      january,   1, 31, 31
  643.      february,  2, 28, 29
  644.      march,     3, 31, 31
  645.      april,     4, 30, 30
  646.      may,       5, 31, 31
  647.      june,      6, 30, 30
  648.      july,      7, 31, 31
  649.      august,    8, 31, 31
  650.      september, 9, 30, 30
  651.      october,  10, 31, 31
  652.      november, 11, 30, 30
  653.      december, 12, 31, 31
  654.  
  655.    Separating the `struct' declaration from the list of keywords and
  656. other fields are a pair of consecutive percent signs, `%%', appearing
  657. left justified in the first column, as in the UNIX utility `lex'.
  658.  
  659.    Using a syntax similar to GNU utilities `flex' and `bison', it is
  660. possible to directly include C source text and comments verbatim into
  661. the generated output file.  This is accomplished by enclosing the region
  662. inside left-justified surrounding `%{', `%}' pairs.  Here is an input
  663. fragment based on the previous example that illustrates this feature:
  664.  
  665.      %{
  666.      #include <assert.h>
  667.      /* This section of code is inserted directly into the output. */
  668.      int return_month_days (struct months *months, int is_leap_year);
  669.      %}
  670.      struct months { char *name; int number; int days; int leap_days; };
  671.      %%
  672.      january,   1, 31, 31
  673.      february,  2, 28, 29
  674.      march,     3, 31, 31
  675.      ...
  676.  
  677.    It is possible to omit the declaration section entirely.  In this
  678. case the keyfile begins directly with the first keyword line, e.g.:
  679.  
  680.      january,   1, 31, 31
  681.      february,  2, 28, 29
  682.      march,     3, 31, 31
  683.      april,     4, 30, 30
  684.      ...
  685.  
  686. 
  687. File: gperf.info,  Node: Keywords,  Next: Functions,  Prev: Declarations,  Up: Input Format
  688.  
  689. Format for Keyword Entries
  690. --------------------------
  691.  
  692.    The second keyfile format section contains lines of keywords and any
  693. associated attributes you might supply.  A line beginning with `#' in
  694. the first column is considered a comment.  Everything following the `#'
  695. is ignored, up to and including the following newline.
  696.  
  697.    The first field of each non-comment line is always the key itself.
  698. It can be given in two ways: as a simple name, i.e., without surrounding
  699. string quotation marks, or as a string enclosed in double-quotes, in C
  700. syntax, possibly with backslash escapes like `\"' or `\234' or `\xa8'.
  701. In either case, it must start right at the beginning of the line,
  702. without leading whitespace.  In this context, a "field" is considered
  703. to extend up to, but not include, the first blank, comma, or newline.
  704. Here is a simple example taken from a partial list of C reserved words:
  705.  
  706.      # These are a few C reserved words, see the c.gperf file
  707.      # for a complete list of ANSI C reserved words.
  708.      unsigned
  709.      sizeof
  710.      switch
  711.      signed
  712.      if
  713.      default
  714.      for
  715.      while
  716.      return
  717.  
  718.    Note that unlike `flex' or `bison' the first `%%' marker may be
  719. elided if the declaration section is empty.
  720.  
  721.    Additional fields may optionally follow the leading keyword.  Fields
  722. should be separated by commas, and terminate at the end of line.  What
  723. these fields mean is entirely up to you; they are used to initialize the
  724. elements of the user-defined `struct' provided by you in the
  725. declaration section.  If the `-t' option is _not_ enabled these fields
  726. are simply ignored.  All previous examples except the last one contain
  727. keyword attributes.
  728.  
  729. 
  730. File: gperf.info,  Node: Functions,  Prev: Keywords,  Up: Input Format
  731.  
  732. Including Additional C Functions
  733. --------------------------------
  734.  
  735.    The optional third section also corresponds closely with conventions
  736. found in `flex' and `bison'.  All text in this section, starting at the
  737. final `%%' and extending to the end of the input file, is included
  738. verbatim into the generated output file.  Naturally, it is your
  739. responsibility to ensure that the code contained in this section is
  740. valid C.
  741.  
  742. 
  743. File: gperf.info,  Node: Output Format,  Next: Binary Strings,  Prev: Input Format,  Up: Description
  744.  
  745. Output Format for Generated C Code with `gperf'
  746. ===============================================
  747.  
  748.    Several options control how the generated C code appears on the
  749. standard output.  Two C function are generated.  They are called `hash'
  750. and `in_word_set', although you may modify their names with a
  751. command-line option.  Both functions require two arguments, a string,
  752. `char *' STR, and a length parameter, `int' LEN.  Their default
  753. function prototypes are as follows:
  754.  
  755.  - Function: unsigned int hash (const char * STR, unsigned int LEN)
  756.      By default, the generated `hash' function returns an integer value
  757.      created by adding LEN to several user-specified STR key positions
  758.      indexed into an "associated values" table stored in a local static
  759.      array.  The associated values table is constructed internally by
  760.      `gperf' and later output as a static local C array called
  761.      `hash_table'; its meaning and properties are described below
  762.      (*note Implementation::). The relevant key positions are specified
  763.      via the `-k' option when running `gperf', as detailed in the
  764.      _Options_ section below(*note Options::).
  765.  
  766.  - Function:  in_word_set (const char * STR, unsigned int LEN)
  767.      If STR is in the keyword set, returns a pointer to that keyword.
  768.      More exactly, if the option `-t' was given, it returns a pointer
  769.      to the matching keyword's structure. Otherwise it returns `NULL'.
  770.  
  771.    If the option `-c' is not used, STR must be a NUL terminated string
  772. of exactly length LEN. If `-c' is used, STR must simply be an array of
  773. LEN characters and does not need to be NUL terminated.
  774.  
  775.    The code generated for these two functions is affected by the
  776. following options:
  777.  
  778. `-t'
  779. `--struct-type'
  780.      Make use of the user-defined `struct'.
  781.  
  782. `-S TOTAL-SWITCH-STATEMENTS'
  783. `--switch=TOTAL-SWITCH-STATEMENTS'
  784.      Generate 1 or more C `switch' statement rather than use a large,
  785.      (and potentially sparse) static array.  Although the exact time and
  786.      space savings of this approach vary according to your C compiler's
  787.      degree of optimization, this method often results in smaller and
  788.      faster code.
  789.  
  790.    If the `-t' and `-S' options are omitted, the default action is to
  791. generate a `char *' array containing the keys, together with additional
  792. null strings used for padding the array.  By experimenting with the
  793. various input and output options, and timing the resulting C code, you
  794. can determine the best option choices for different keyword set
  795. characteristics.
  796.  
  797. 
  798. File: gperf.info,  Node: Binary Strings,  Prev: Output Format,  Up: Description
  799.  
  800. Use of NUL characters
  801. =====================
  802.  
  803.    By default, the code generated by `gperf' operates on zero
  804. terminated strings, the usual representation of strings in C. This means
  805. that the keywords in the input file must not contain NUL characters,
  806. and the STR argument passed to `hash' or `in_word_set' must be NUL
  807. terminated and have exactly length LEN.
  808.  
  809.    If option `-c' is used, then the STR argument does not need to be
  810. NUL terminated. The code generated by `gperf' will only access the
  811. first LEN, not LEN+1, bytes starting at STR.  However, the keywords in
  812. the input file still must not contain NUL characters.
  813.  
  814.    If option `-l' is used, then the hash table performs binary
  815. comparison. The keywords in the input file may contain NUL characters,
  816. written in string syntax as `\000' or `\x00', and the code generated by
  817. `gperf' will treat NUL like any other character.  Also, in this case
  818. the `-c' option is ignored.
  819.  
  820. 
  821. File: gperf.info,  Node: Options,  Next: Bugs,  Prev: Description,  Up: Top
  822.  
  823. Invoking `gperf'
  824. ****************
  825.  
  826.    There are _many_ options to `gperf'.  They were added to make the
  827. program more convenient for use with real applications.  "On-line" help
  828. is readily available via the `-h' option.  Here is the complete list of
  829. options.
  830.  
  831. * Menu:
  832.  
  833. * Input Details::               Options that affect Interpretation of the Input File
  834. * Output Language::             Specifying the Language for the Output Code
  835. * Output Details::              Fine tuning Details in the Output Code
  836. * Algorithmic Details::         Changing the Algorithms employed by `gperf'
  837. * Verbosity::                   Informative Output
  838.  
  839. 
  840. File: gperf.info,  Node: Input Details,  Next: Output Language,  Prev: Options,  Up: Options
  841.  
  842. Options that affect Interpretation of the Input File
  843. ====================================================
  844.  
  845. `-e KEYWORD-DELIMITER-LIST'
  846. `--delimiters=KEYWORD-DELIMITER-LIST'
  847.      Allows the user to provide a string containing delimiters used to
  848.      separate keywords from their attributes.  The default is ",\n".
  849.      This option is essential if you want to use keywords that have
  850.      embedded commas or newlines.  One useful trick is to use -e'TAB',
  851.      where TAB is the literal tab character.
  852.  
  853. `-t'
  854. `--struct-type'
  855.      Allows you to include a `struct' type declaration for generated
  856.      code.  Any text before a pair of consecutive `%%' is considered
  857.      part of the type declaration.  Keywords and additional fields may
  858.      follow this, one group of fields per line.  A set of examples for
  859.      generating perfect hash tables and functions for Ada, C, C++,
  860.      Pascal, Modula 2, Modula 3 and JavaScript reserved words are
  861.      distributed with this release.
  862.  
  863. 
  864. File: gperf.info,  Node: Output Language,  Next: Output Details,  Prev: Input Details,  Up: Options
  865.  
  866. Options to specify the Language for the Output Code
  867. ===================================================
  868.  
  869. `-L GENERATED-LANGUAGE-NAME'
  870. `--language=GENERATED-LANGUAGE-NAME'
  871.      Instructs `gperf' to generate code in the language specified by the
  872.      option's argument.  Languages handled are currently:
  873.  
  874.     `KR-C'
  875.           Old-style K&R C. This language is understood by old-style C
  876.           compilers and ANSI C compilers, but ANSI C compilers may flag
  877.           warnings (or even errors) because of lacking `const'.
  878.  
  879.     `C'
  880.           Common C. This language is understood by ANSI C compilers,
  881.           and also by old-style C compilers, provided that you `#define
  882.           const' to empty for compilers which don't know about this
  883.           keyword.
  884.  
  885.     `ANSI-C'
  886.           ANSI C. This language is understood by ANSI C compilers and
  887.           C++ compilers.
  888.  
  889.     `C++'
  890.           C++. This language is understood by C++ compilers.
  891.  
  892.      The default is C.
  893.  
  894. `-a'
  895.      This option is supported for compatibility with previous releases
  896.      of `gperf'. It does not do anything.
  897.  
  898. `-g'
  899.      This option is supported for compatibility with previous releases
  900.      of `gperf'. It does not do anything.
  901.  
  902. 
  903. File: gperf.info,  Node: Output Details,  Next: Algorithmic Details,  Prev: Output Language,  Up: Options
  904.  
  905. Options for fine tuning Details in the Output Code
  906. ==================================================
  907.  
  908. `-K KEY-NAME'
  909. `--slot-name=KEY-NAME'
  910.      This option is only useful when option `-t' has been given.  By
  911.      default, the program assumes the structure component identifier for
  912.      the keyword is `name'.  This option allows an arbitrary choice of
  913.      identifier for this component, although it still must occur as the
  914.      first field in your supplied `struct'.
  915.  
  916. `-F INITIALIZERS'
  917. `--initializer-suffix=INITIALIZERS'
  918.      This option is only useful when option `-t' has been given.  It
  919.      permits to specify initializers for the structure members following
  920.      KEY NAME in empty hash table entries.  The list of initializers
  921.      should start with a comma.  By default, the emitted code will
  922.      zero-initialize structure members following KEY NAME.
  923.  
  924. `-H HASH-FUNCTION-NAME'
  925. `--hash-fn-name=HASH-FUNCTION-NAME'
  926.      Allows you to specify the name for the generated hash function.
  927.      Default name is `hash'.  This option permits the use of two hash
  928.      tables in the same file.
  929.  
  930. `-N LOOKUP-FUNCTION-NAME'
  931. `--lookup-fn-name=LOOKUP-FUNCTION-NAME'
  932.      Allows you to specify the name for the generated lookup function.
  933.      Default name is `in_word_set'.  This option permits completely
  934.      automatic generation of perfect hash functions, especially when
  935.      multiple generated hash functions are used in the same application.
  936.  
  937. `-Z CLASS-NAME'
  938. `--class-name=CLASS-NAME'
  939.      This option is only useful when option `-L C++' has been given.  It
  940.      allows you to specify the name of generated C++ class.  Default
  941.      name is `Perfect_Hash'.
  942.  
  943. `-7'
  944. `--seven-bit'
  945.      This option specifies that all strings that will be passed as
  946.      arguments to the generated hash function and the generated lookup
  947.      function will solely consist of 7-bit ASCII characters (characters
  948.      in the range 0..127).  (Note that the ANSI C functions `isalnum'
  949.      and `isgraph' do _not_ guarantee that a character is in this
  950.      range. Only an explicit test like `c >= 'A' && c <= 'Z''
  951.      guarantees this.) This was the default in versions of `gperf'
  952.      earlier than 2.7; now the default is to assume 8-bit characters.
  953.  
  954. `-c'
  955. `--compare-strncmp'
  956.      Generates C code that uses the `strncmp' function to perform
  957.      string comparisons.  The default action is to use `strcmp'.
  958.  
  959. `-C'
  960. `--readonly-tables'
  961.      Makes the contents of all generated lookup tables constant, i.e.,
  962.      "readonly".  Many compilers can generate more efficient code for
  963.      this by putting the tables in readonly memory.
  964.  
  965. `-E'
  966. `--enum'
  967.      Define constant values using an enum local to the lookup function
  968.      rather than with #defines.  This also means that different lookup
  969.      functions can reside in the same file.  Thanks to James Clark
  970.      `<jjc@ai.mit.edu>'.
  971.  
  972. `-I'
  973. `--includes'
  974.      Include the necessary system include file, `<string.h>', at the
  975.      beginning of the code.  By default, this is not done; the user must
  976.      include this header file himself to allow compilation of the code.
  977.  
  978. `-G'
  979. `--global'
  980.      Generate the static table of keywords as a static global variable,
  981.      rather than hiding it inside of the lookup function (which is the
  982.      default behavior).
  983.  
  984. `-W HASH-TABLE-ARRAY-NAME'
  985. `--word-array-name=HASH-TABLE-ARRAY-NAME'
  986.      Allows you to specify the name for the generated array containing
  987.      the hash table.  Default name is `wordlist'.  This option permits
  988.      the use of two hash tables in the same file, even when the option
  989.      `-G' is given.
  990.  
  991. `-S TOTAL-SWITCH-STATEMENTS'
  992. `--switch=TOTAL-SWITCH-STATEMENTS'
  993.      Causes the generated C code to use a `switch' statement scheme,
  994.      rather than an array lookup table.  This can lead to a reduction
  995.      in both time and space requirements for some keyfiles.  The
  996.      argument to this option determines how many `switch' statements
  997.      are generated. A value of 1 generates 1 `switch' containing all
  998.      the elements, a value of 2 generates 2 tables with 1/2 the
  999.      elements in each `switch', etc.  This is useful since many C
  1000.      compilers cannot correctly generate code for large `switch'
  1001.      statements. This option was inspired in part by Keith Bostic's
  1002.      original C program.
  1003.  
  1004. `-T'
  1005. `--omit-struct-type'
  1006.      Prevents the transfer of the type declaration to the output file.
  1007.      Use this option if the type is already defined elsewhere.
  1008.  
  1009. `-p'
  1010.      This option is supported for compatibility with previous releases
  1011.      of `gperf'. It does not do anything.
  1012.  
  1013. 
  1014. File: gperf.info,  Node: Algorithmic Details,  Next: Verbosity,  Prev: Output Details,  Up: Options
  1015.  
  1016. Options for changing the Algorithms employed by `gperf'
  1017. =======================================================
  1018.  
  1019. `-k KEYS'
  1020. `--key-positions=KEYS'
  1021.      Allows selection of the character key positions used in the
  1022.      keywords' hash function. The allowable choices range between
  1023.      1-126, inclusive.  The positions are separated by commas, e.g.,
  1024.      `-k 9,4,13,14'; ranges may be used, e.g., `-k 2-7'; and positions
  1025.      may occur in any order.  Furthermore, the meta-character '*'
  1026.      causes the generated hash function to consider *all* character
  1027.      positions in each key, whereas '$' instructs the hash function to
  1028.      use the "final character" of a key (this is the only way to use a
  1029.      character position greater than 126, incidentally).
  1030.  
  1031.      For instance, the option `-k 1,2,4,6-10,'$'' generates a hash
  1032.      function that considers positions 1,2,4,6,7,8,9,10, plus the last
  1033.      character in each key (which may differ for each key, obviously).
  1034.      Keys with length less than the indicated key positions work
  1035.      properly, since selected key positions exceeding the key length
  1036.      are simply not referenced in the hash function.
  1037.  
  1038. `-l'
  1039. `--compare-strlen'
  1040.      Compare key lengths before trying a string comparison.  This might
  1041.      cut down on the number of string comparisons made during the
  1042.      lookup, since keys with different lengths are never compared via
  1043.      `strcmp'.  However, using `-l' might greatly increase the size of
  1044.      the generated C code if the lookup table range is large (which
  1045.      implies that the switch option `-S' is not enabled), since the
  1046.      length table contains as many elements as there are entries in the
  1047.      lookup table.  This option is mandatory for binary comparisons
  1048.      (*note Binary Strings::).
  1049.  
  1050. `-D'
  1051. `--duplicates'
  1052.      Handle keywords whose key position sets hash to duplicate values.
  1053.      Duplicate hash values occur for two reasons:
  1054.  
  1055.         * Since `gperf' does not backtrack it is possible for it to
  1056.           process all your input keywords without finding a unique
  1057.           mapping for each word.  However, frequently only a very small
  1058.           number of duplicates occur, and the majority of keys still
  1059.           require one probe into the table.
  1060.  
  1061.         * Sometimes a set of keys may have the same names, but possess
  1062.           different attributes.  With the -D option `gperf' treats all
  1063.           these keys as part of an equivalence class and generates a
  1064.           perfect hash function with multiple comparisons for duplicate
  1065.           keys.  It is up to you to completely disambiguate the
  1066.           keywords by modifying the generated C code.  However, `gperf'
  1067.           helps you out by organizing the output.
  1068.  
  1069.      Option `-D' is extremely useful for certain large or highly
  1070.      redundant keyword sets, e.g., assembler instruction opcodes.
  1071.      Using this option usually means that the generated hash function
  1072.      is no longer perfect.  On the other hand, it permits `gperf' to
  1073.      work on keyword sets that it otherwise could not handle.
  1074.  
  1075. `-f ITERATION-AMOUNT'
  1076. `--fast=ITERATION-AMOUNT'
  1077.      Generate the perfect hash function "fast".  This decreases
  1078.      `gperf''s running time at the cost of minimizing generated
  1079.      table-size.  The iteration amount represents the number of times to
  1080.      iterate when resolving a collision.  `0' means iterate by the
  1081.      number of keywords.  This option is probably most useful when used
  1082.      in conjunction with options `-D' and/or `-S' for _large_ keyword
  1083.      sets.
  1084.  
  1085. `-i INITIAL-VALUE'
  1086. `--initial-asso=INITIAL-VALUE'
  1087.      Provides an initial VALUE for the associate values array.  Default
  1088.      is 0.  Increasing the initial value helps inflate the final table
  1089.      size, possibly leading to more time efficient keyword lookups.
  1090.      Note that this option is not particularly useful when `-S' is
  1091.      used.  Also, `-i' is overridden when the `-r' option is used.
  1092.  
  1093. `-j JUMP-VALUE'
  1094. `--jump=JUMP-VALUE'
  1095.      Affects the "jump value", i.e., how far to advance the associated
  1096.      character value upon collisions.  JUMP-VALUE is rounded up to an
  1097.      odd number, the default is 5.  If the JUMP-VALUE is 0 `gperf'
  1098.      jumps by random amounts.
  1099.  
  1100. `-n'
  1101. `--no-strlen'
  1102.      Instructs the generator not to include the length of a keyword when
  1103.      computing its hash value.  This may save a few assembly
  1104.      instructions in the generated lookup table.
  1105.  
  1106. `-o'
  1107. `--occurrence-sort'
  1108.      Reorders the keywords by sorting the keywords so that frequently
  1109.      occuring key position set components appear first.  A second
  1110.      reordering pass follows so that keys with "already determined
  1111.      values" are placed towards the front of the keylist.  This may
  1112.      decrease the time required to generate a perfect hash function for
  1113.      many keyword sets, and also produce more minimal perfect hash
  1114.      functions.  The reason for this is that the reordering helps prune
  1115.      the search time by handling inevitable collisions early in the
  1116.      search process.  On the other hand, if the number of keywords is
  1117.      _very_ large using `-o' may _increase_ `gperf''s execution time,
  1118.      since collisions will begin earlier and continue throughout the
  1119.      remainder of keyword processing.  See Cichelli's paper from the
  1120.      January 1980 Communications of the ACM for details.
  1121.  
  1122. `-r'
  1123. `--random'
  1124.      Utilizes randomness to initialize the associated values table.
  1125.      This frequently generates solutions faster than using deterministic
  1126.      initialization (which starts all associated values at 0).
  1127.      Furthermore, using the randomization option generally increases
  1128.      the size of the table.  If `gperf' has difficultly with a certain
  1129.      keyword set try using `-r' or `-D'.
  1130.  
  1131. `-s SIZE-MULTIPLE'
  1132. `--size-multiple=SIZE-MULTIPLE'
  1133.      Affects the size of the generated hash table.  The numeric
  1134.      argument for this option indicates "how many times larger or
  1135.      smaller" the maximum associated value range should be, in
  1136.      relationship to the number of keys.  If the SIZE-MULTIPLE is
  1137.      negative the maximum associated value is calculated by _dividing_
  1138.      it into the total number of keys.  For example, a value of 3 means
  1139.      "allow the maximum associated value to be about 3 times larger
  1140.      than the number of input keys".
  1141.  
  1142.      Conversely, a value of -3 means "allow the maximum associated
  1143.      value to be about 3 times smaller than the number of input keys".
  1144.      Negative values are useful for limiting the overall size of the
  1145.      generated hash table, though this usually increases the number of
  1146.      duplicate hash values.
  1147.  
  1148.      If `generate switch' option `-S' is _not_ enabled, the maximum
  1149.      associated value influences the static array table size, and a
  1150.      larger table should decrease the time required for an unsuccessful
  1151.      search, at the expense of extra table space.
  1152.  
  1153.      The default value is 1, thus the default maximum associated value
  1154.      about the same size as the number of keys (for efficiency, the
  1155.      maximum associated value is always rounded up to a power of 2).
  1156.      The actual table size may vary somewhat, since this technique is
  1157.      essentially a heuristic.  In particular, setting this value too
  1158.      high slows down `gperf''s runtime, since it must search through a
  1159.      much larger range of values.  Judicious use of the `-f' option
  1160.      helps alleviate this overhead, however.
  1161.  
  1162. 
  1163. File: gperf.info,  Node: Verbosity,  Prev: Algorithmic Details,  Up: Options
  1164.  
  1165. Informative Output
  1166. ==================
  1167.  
  1168. `-h'
  1169. `--help'
  1170.      Prints a short summary on the meaning of each program option.
  1171.      Aborts further program execution.
  1172.  
  1173. `-v'
  1174. `--version'
  1175.      Prints out the current version number.
  1176.  
  1177. `-d'
  1178. `--debug'
  1179.      Enables the debugging option.  This produces verbose diagnostics to
  1180.      "standard error" when `gperf' is executing.  It is useful both for
  1181.      maintaining the program and for determining whether a given set of
  1182.      options is actually speeding up the search for a solution.  Some
  1183.      useful information is dumped at the end of the program when the
  1184.      `-d' option is enabled.
  1185.  
  1186. 
  1187. File: gperf.info,  Node: Bugs,  Next: Projects,  Prev: Options,  Up: Top
  1188.  
  1189. Known Bugs and Limitations with `gperf'
  1190. ***************************************
  1191.  
  1192.    The following are some limitations with the current release of
  1193. `gperf':
  1194.  
  1195.    * The `gperf' utility is tuned to execute quickly, and works quickly
  1196.      for small to medium size data sets (around 1000 keywords).  It is
  1197.      extremely useful for maintaining perfect hash functions for
  1198.      compiler keyword sets.  Several recent enhancements now enable
  1199.      `gperf' to work efficiently on much larger keyword sets (over
  1200.      15,000 keywords).  When processing large keyword sets it helps
  1201.      greatly to have over 8 megs of RAM.
  1202.  
  1203.      However, since `gperf' does not backtrack no guaranteed solution
  1204.      occurs on every run.  On the other hand, it is usually easy to
  1205.      obtain a solution by varying the option parameters.  In
  1206.      particular, try the `-r' option, and also try changing the default
  1207.      arguments to the `-s' and `-j' options.  To _guarantee_ a
  1208.      solution, use the `-D' and `-S' options, although the final
  1209.      results are not likely to be a _perfect_ hash function anymore!
  1210.      Finally, use the `-f' option if you want `gperf' to generate the
  1211.      perfect hash function _fast_, with less emphasis on making it
  1212.      minimal.
  1213.  
  1214.    * The size of the generate static keyword array can get _extremely_
  1215.      large if the input keyword file is large or if the keywords are
  1216.      quite similar.  This tends to slow down the compilation of the
  1217.      generated C code, and _greatly_ inflates the object code size.  If
  1218.      this situation occurs, consider using the `-S' option to reduce
  1219.      data size, potentially increasing keyword recognition time a
  1220.      negligible amount.  Since many C compilers cannot correctly
  1221.      generated code for large switch statements it is important to
  1222.      qualify the -S option with an appropriate numerical argument that
  1223.      controls the number of switch statements generated.
  1224.  
  1225.    * The maximum number of key positions selected for a given key has an
  1226.      arbitrary limit of 126.  This restriction should be removed, and if
  1227.      anyone considers this a problem write me and let me know so I can
  1228.      remove the constraint.
  1229.  
  1230. 
  1231. File: gperf.info,  Node: Projects,  Next: Implementation,  Prev: Bugs,  Up: Top
  1232.  
  1233. Things Still Left to Do
  1234. ***********************
  1235.  
  1236.    It should be "relatively" easy to replace the current perfect hash
  1237. function algorithm with a more exhaustive approach; the perfect hash
  1238. module is essential independent from other program modules.  Additional
  1239. worthwhile improvements include:
  1240.  
  1241.    * Make the algorithm more robust.  At present, the program halts
  1242.      with an error diagnostic if it can't find a direct solution and
  1243.      the `-D' option is not enabled.  A more comprehensive, albeit
  1244.      computationally expensive, approach would employ backtracking or
  1245.      enable alternative options and retry.  It's not clear how helpful
  1246.      this would be, in general, since most search sets are rather small
  1247.      in practice.
  1248.  
  1249.    * Another useful extension involves modifying the program to generate
  1250.      "minimal" perfect hash functions (under certain circumstances, the
  1251.      current version can be rather extravagant in the generated table
  1252.      size).  Again, this is mostly of theoretical interest, since a
  1253.      sparse table often produces faster lookups, and use of the `-S'
  1254.      `switch' option can minimize the data size, at the expense of
  1255.      slightly longer lookups (note that the gcc compiler generally
  1256.      produces good code for `switch' statements, reducing the need for
  1257.      more complex schemes).
  1258.  
  1259.    * In addition to improving the algorithm, it would also be useful to
  1260.      generate a C++ class or Ada package as the code output, in
  1261.      addition to the current C routines.
  1262.  
  1263. 
  1264. File: gperf.info,  Node: Implementation,  Next: Bibliography,  Prev: Projects,  Up: Top
  1265.  
  1266. Implementation Details of GNU `gperf'
  1267. *************************************
  1268.  
  1269.    A paper describing the high-level description of the data structures
  1270. and algorithms used to implement `gperf' will soon be available.  This
  1271. paper is useful not only from a maintenance and enhancement perspective,
  1272. but also because they demonstrate several clever and useful programming
  1273. techniques, e.g., `Iteration Number' boolean arrays, double hashing, a
  1274. "safe" and efficient method for reading arbitrarily long input from a
  1275. file, and a provably optimal algorithm for simultaneously determining
  1276. both the minimum and maximum elements in a list.
  1277.  
  1278. 
  1279. File: gperf.info,  Node: Bibliography,  Next: Concept Index,  Prev: Implementation,  Up: Top
  1280.  
  1281. Bibliography
  1282. ************
  1283.  
  1284.    [1] Chang, C.C.: A Scheme for Constructing Ordered Minimal Perfect
  1285. Hashing Functions Information Sciences 39(1986), 187-195.
  1286.  
  1287.    [2] Cichelli, Richard J. Author's Response to "On Cichelli's Minimal
  1288. Perfect Hash Functions Method" Communications of the ACM, 23,
  1289. 12(December 1980), 729.
  1290.  
  1291.    [3] Cichelli, Richard J. Minimal Perfect Hash Functions Made Simple
  1292. Communications of the ACM, 23, 1(January 1980), 17-19.
  1293.  
  1294.    [4] Cook, C. R. and Oldehoeft, R.R. A Letter Oriented Minimal
  1295. Perfect Hashing Function SIGPLAN Notices, 17, 9(September 1982), 18-27.
  1296.  
  1297.    [5] Cormack, G. V. and Horspool, R. N. S. and Kaiserwerth, M.
  1298. Practical Perfect Hashing Computer Journal, 28, 1(January 1985), 54-58.
  1299.  
  1300.    [6] Jaeschke, G. Reciprocal Hashing: A Method for Generating Minimal
  1301. Perfect Hashing Functions Communications of the ACM, 24, 12(December
  1302. 1981), 829-833.
  1303.  
  1304.    [7] Jaeschke, G. and Osterburg, G. On Cichelli's Minimal Perfect
  1305. Hash Functions Method Communications of the ACM, 23, 12(December 1980),
  1306. 728-729.
  1307.  
  1308.    [8] Sager, Thomas J. A Polynomial Time Generator for Minimal Perfect
  1309. Hash Functions Communications of the ACM, 28, 5(December 1985), 523-532
  1310.  
  1311.    [9] Schmidt, Douglas C. GPERF: A Perfect Hash Function Generator
  1312. Second USENIX C++ Conference Proceedings, April 1990.
  1313.  
  1314.    [10] Sebesta, R.W. and Taylor, M.A. Minimal Perfect Hash Functions
  1315. for Reserved Word Lists  SIGPLAN Notices, 20, 12(September 1985), 47-53.
  1316.  
  1317.    [11] Sprugnoli, R. Perfect Hashing Functions: A Single Probe
  1318. Retrieving Method for Static Sets Communications of the ACM, 20
  1319. 11(November 1977), 841-850.
  1320.  
  1321.    [12] Stallman, Richard M. Using and Porting GNU CC Free Software
  1322. Foundation, 1988.
  1323.  
  1324.    [13] Stroustrup, Bjarne The C++ Programming Language.
  1325. Addison-Wesley, 1986.
  1326.  
  1327.    [14] Tiemann, Michael D. User's Guide to GNU C++ Free Software
  1328. Foundation, 1989.
  1329.  
  1330. 
  1331. File: gperf.info,  Node: Concept Index,  Prev: Bibliography,  Up: Top
  1332.  
  1333. Concept Index
  1334. *************
  1335.  
  1336. * Menu:
  1337.  
  1338. * %%:                                    Declarations.
  1339. * %{:                                    Declarations.
  1340. * %}:                                    Declarations.
  1341. * Array name:                            Output Details.
  1342. * Bugs:                                  Contributors.
  1343. * Class name:                            Output Details.
  1344. * Declaration section:                   Input Format.
  1345. * Delimiters:                            Input Details.
  1346. * Duplicates:                            Algorithmic Details.
  1347. * Format:                                Input Format.
  1348. * Functions section:                     Input Format.
  1349. * hash:                                  Output Format.
  1350. * hash table:                            Output Format.
  1351. * in_word_set:                           Output Format.
  1352. * Initializers:                          Output Details.
  1353. * Jump value:                            Algorithmic Details.
  1354. * Keywords section:                      Input Format.
  1355. * Minimal perfect hash functions:        Search Structures.
  1356. * NUL:                                   Binary Strings.
  1357. * Slot name:                             Output Details.
  1358. * Static search structure:               Search Structures.
  1359. * switch <1>:                            Output Details.
  1360. * switch:                                Output Format.
  1361.  
  1362.  
  1363. 
  1364. Tag Table:
  1365. Node: Top1236
  1366. Node: Copying3130
  1367. Node: Contributors22321
  1368. Node: Motivation23580
  1369. Node: Search Structures24656
  1370. Node: Description28201
  1371. Node: Input Format30102
  1372. Node: Declarations30944
  1373. Node: Keywords33268
  1374. Node: Functions35023
  1375. Node: Output Format35517
  1376. Node: Binary Strings38113
  1377. Node: Options39119
  1378. Node: Input Details39825
  1379. Node: Output Language40890
  1380. Node: Output Details42194
  1381. Node: Algorithmic Details46842
  1382. Node: Verbosity54284
  1383. Node: Bugs54987
  1384. Node: Projects57215
  1385. Node: Implementation58792
  1386. Node: Bibliography59509
  1387. Node: Concept Index61452
  1388. 
  1389. End Tag Table
  1390.